package bookez.model.businessobject;

public abstract class BusinessObject {

	protected boolean blindlyEquals( Object obj ) {
		return super.equals( obj );
	}//end method blindlyEquals
	
	protected boolean checkProperty( Object thisObj, Object other ) {
		if( thisObj != null && other != null ) {			
			return thisObj.equals( other );
		}
		return false;
	}//end method checkProperty
	
	protected boolean processResult( boolean[] values ) {
		for( boolean value : values ) {
			if( value == false ) {
				return false;
			}//end if
		}//end for
		return true;
	}//end method andBoolean
	
	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		if( this == obj ) { return true; }
		if( obj == null ) { return false; }
		if( !(obj instanceof BusinessObject ) ) { return false; }
		
		return this.blindlyEquals( obj ) && ((BusinessObject)obj).blindlyEquals( this );
	}//end method equals
	
	protected int toHashCode() {
		return this.hashCodeSeed.hashCode();
	}//end toHashCode
	
	protected void addPropertyToHashCode( Object property ) {
		this.hashCodeSeed += (property != null ) ? property.toString() : "null";
	}//end method addPropertyToHashCode
		
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return toHashCode();
	}//end method hashCode
	
	protected void addInfo( String propertyName, Object property ) {
		String value = ( property != null ) ? property.toString() : "null";
		infoBuilder.append( propertyName +"="+ value + "," );
	}//end method addInfo
	
	protected String createInfo() {
		infoBuilder.replace( infoBuilder.length() - 1, infoBuilder.length(), "]");
		return infoBuilder.toString();
	}//end method getObjectInfo
	
	private String hashCodeSeed = "31";
	private StringBuilder infoBuilder = new StringBuilder( this.getClass().getSimpleName() + "[");
}//end class BusinessObject
